package com.liuyou.weather2;


import java.util.ArrayList;

public class WeatherData implements Subject {
    private double temperature;
    private double pressure;
    private double humidity;
    private ArrayList<Observer> observers;
//    private WeatherWebsideCurrentCondition weatherWebsideCurrentCondition;


/*    public WeatherData(WeatherWebsideCurrentCondition weatherWebsideCurrentCondition) {
        this.weatherWebsideCurrentCondition = weatherWebsideCurrentCondition;
    }*/

    public WeatherData() {
        observers = new ArrayList<Observer>();
    }

    public WeatherData(ArrayList<Observer> observers) {
        this.observers = observers;
    }

    public void setData(double temperature, double pressure, double humidity) {
        this.temperature = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
        dataChange();
    }

/*    public void dataChange() {
        weatherWebsideCurrentCondition.update(temperature, pressure, humidity);
    }*/

    public void dataChange() {
        notifyObserver();
    }

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        if (observers.contains(observer)) {
            observers.remove(observer);
        }
    }

    @Override
    public void notifyObserver() {
/*        for (int i = 0; i < observers.size(); i++) {
            observers.get(i).update(temperature, pressure, humidity);
        }*/
        for (Observer value : observers) {
            value.update(temperature, pressure, humidity);
        }
    }
}
